/**
 * 向指定元素添加鼠标移动事件监听，并且在鼠标抬起时移除事件监听
 *
 * @param {HTMLElement} el 需要添加鼠标移动事件监听的元素
 * @param {(this:HTMLElement, evt: MouseEvent) => any} handler 鼠标移动事件监听处理函数
 */
export const addMouseMoveEvtListener = (
  el: HTMLElement,
  handler: (this: HTMLElement, evt: MouseEvent) => any
) => {
  const handleUp = () => {
    el.removeEventListener('mousemove', handler)
    el.removeEventListener('mouseup', handleUp)
  }

  el.addEventListener('mousemove', handler)
  el.addEventListener('mouseup', handleUp)
}

export type AddMouseMoveEvtListenerType = typeof addMouseMoveEvtListener
